package com.example.backend.service;
import com.example.backend.entity.Book;
import com.example.backend.mapper.BookMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookService {

    private BookMapper bookMapper;

    @Autowired
    public BookService(BookMapper bookMapper){
        this.bookMapper = bookMapper;
    }

    public List<Book> getAllBooks(){
        List<Book> books= bookMapper.getAllBooks();
        return books;
    }

    public boolean addBooks(@Param("bookId") int id, @Param("bookName") String name, @Param("author") String author, @Param("num") int num){
        int book = bookMapper.addBooks(id,name,author,num);
        if(book == 0)
            return false;
        else
            return true;
    }
    public List<Book> getBooks(@Param("bookName") String name){
        List<Book> books = bookMapper.getBooks(name);
        return books;
    }
    public boolean deleteBooks(@Param("bookName") String name){
        int book = bookMapper.deleteBooks(name);
        if(book == 0 )
            return false;
        else
            return true;
    }
    public boolean updateBooks(@Param("bookId") int id, @Param("bookName") String name, @Param("author") String author, @Param("num") int num){
        int book = bookMapper.updateBooks(id,name,author,num);
        if(book == 0)
            return false;
        else
            return true;
    }
}
